#pragma once

namespace util
{
	// stores POD-like types
	template <typename T>
	class Array
	{
	public:
		Array(uint size)
		{
			Elements = new T[size];
			mSize = size;
			NumElements = 0;
		}

		Array(const Array & src)
		{
			Elements = new T[src.mSize];
			mSize = src.mSize;
			NumElements = src.NumElements;

			for(uint i = 0; i < src.NumElements; i++)
			{
				Elements[i] = src.Elements[i];
			}
		}

		Array & operator=(const Array & src)
		{
			if(this != &src)
			{
				Elements = new T[src.mSize];
				mSize = src.mSize;
				NumElements = src.NumElements;

				for(uint i = 0; i < src.NumElements; i++)
				{
					Elements[i] = src.Elements[i];
				}
			}
			return *this;
		}

		~Array()
		{
			delete[] Elements;
		}

		void add(const T & t)
		{
			assert(NumElements < mSize);
			Elements[NumElements++] = t;
		}

		T & back()
		{
			return Elements[NumElements - 1];
		}

		void removeLast()
		{
			NumElements--;
		}

		T & operator[](size_t i)
		{
			return Elements[i];
		}

		const T & operator[](size_t i) const
		{
			return Elements[i];
		}

		T * Elements;
		uint NumElements;

	private:
		uint mSize;
	};
}